import { defineStore } from "pinia";
import { LocalStorage } from "@/utils/storage";

export const BANNER = "ylmall_banner";

export const useBanner = defineStore("banner", {
  state: () => ({
    // 分类缓存数据
    bannerList: LocalStorage.getItem(BANNER) || []
  }),
  actions: {
    getBanner() {
      return this.bannerList;
    },
    saveBanner(banner) {
      if (!banner) return;
      this.bannerList = JSON.parse(banner);
      LocalStorage.setItem(BANNER, banner);
    },
    removeBanner() {
      this.bannerList = [];
      LocalStorage.removeItem(BANNER);
    }
  }
});
